import { SelectableTableView } from "selectable_tree_view.slint";
import { ActiveTab, MainListModel } from "common.slint";
import { SettingsList } from "settings_list.slint";
import { GuiState } from "gui_state.slint";
import { About } from "about.slint";
import { Settings } from "settings.slint";

export component MainList {
    in-out property <[MainListModel]> duplicate_files_model: [];
    in-out property <[MainListModel]> empty_folder_model: [
        {checked: false, selected_row: false, header_row: false, filled_header_row: false, val_str: ["kropkarz", "/Xd1", "24.10.2023"], val_int: []} ,
        {checked: false, selected_row: false, header_row: false, filled_header_row: false, val_str: ["witasphere", "/Xd1/Imagerren2", "25.11.1991"], val_int: []},
        {checked: true, selected_row: false, header_row: false, filled_header_row: false, val_str: ["lokkaler", "/Xd1/Vide2", "01.23.1911"], val_int: []}
    ];
    in-out property <[MainListModel]> big_files_model: [];
    in-out property <[MainListModel]> empty_files_model: [
        {checked: false, selected_row: false, header_row: false, filled_header_row: false, val_str: ["kropkarz", "/Xd1", "24.10.2023"], val_int: []} ,
        {checked: false, selected_row: false, header_row: false, filled_header_row: false, val_str: ["witasphere", "/Xd1/Imagerren2", "25.11.1991"], val_int: []},
        {checked: true, selected_row: false, header_row: false, filled_header_row: false, val_str: ["lokkaler", "/Xd1/Vide2", "01.23.1911"], val_int: []}
    ];
    in-out property <[MainListModel]> temporary_files_model: [];
    in-out property <[MainListModel]> similar_images_model: [
        {checked: false, selected_row: false, header_row: true, filled_header_row: false, val_str: ["Original", "500KB", "100x100", "kropkarz", "/Xd1", "24.10.2023"], val_int: []},
        {checked: false, selected_row: false, header_row: false, filled_header_row: false, val_str: ["Similar", "500KB", "100x100", "witasphere", "/Xd1/Imagerren2", "25.11.1991"], val_int: []},
        {checked: true, selected_row: false, header_row: false, filled_header_row: false, val_str: ["Similar", "500KB", "100x100", "lokkaler", "/Xd1/Vide2", "01.23.1911"], val_int: []}
    ];
    in-out property <[MainListModel]> similar_videos_model: [];
    in-out property <[MainListModel]> similar_music_model: [];
    in-out property <[MainListModel]> invalid_symlinks_model: [];
    in-out property <[MainListModel]> broken_files_model: [];
    in-out property <[MainListModel]> bad_extensions_model: [];

    callback changed_active_tab();

    duplicates := SelectableTableView {
        visible: GuiState.active_tab == ActiveTab.DuplicateFiles;
        min-width: 200px;
        height: parent.height;
        columns <=> Settings.duplicates_column_name;
        column_sizes <=> Settings.duplicates_column_size;
        values <=> duplicate_files_model;
        parentPathIdx: 3;
        fileNameIdx: 2;
    }

    empty_folders := SelectableTableView {
        visible: GuiState.active_tab == ActiveTab.EmptyFolders;
        min-width: 200px;
        height: parent.height;
        columns <=> Settings.empty_folders_column_name;
        column_sizes <=> Settings.empty_folders_column_size;
        values <=> empty_folder_model;
        parentPathIdx: 2;
        fileNameIdx: 1;
    }

    big_files := SelectableTableView {
        visible: GuiState.active_tab == ActiveTab.BigFiles;
        min-width: 200px;
        height: parent.height;
        columns <=> Settings.big_files_column_name;
        column_sizes <=> Settings.big_files_column_size;
        values <=> big_files_model;
        parentPathIdx: 3;
        fileNameIdx: 2;
    }

    empty_files := SelectableTableView {
        visible: GuiState.active_tab == ActiveTab.EmptyFiles;
        min-width: 200px;
        height: parent.height;
        columns <=> Settings.empty_files_column_name;
        column_sizes <=> Settings.empty_files_column_size;
        values <=> empty_files_model;
        parentPathIdx: 2;
        fileNameIdx: 1;
    }

    temporary_files := SelectableTableView {
        visible: GuiState.active_tab == ActiveTab.TemporaryFiles;
        min-width: 200px;
        height: parent.height;
        columns <=> Settings.temporary_files_column_name;
        column_sizes <=> Settings.temporary_files_column_size;
        values <=> temporary_files_model;
        parentPathIdx: 2;
        fileNameIdx: 1;
    }

    similar_images := SelectableTableView {
        visible: GuiState.active_tab == ActiveTab.SimilarImages;
        min-width: 200px;
        height: parent.height;
        columns <=> Settings.similar_images_column_name;
        column_sizes <=> Settings.similar_images_column_size;
        values <=> similar_images_model;
        parentPathIdx: 5;
        fileNameIdx: 4;
    }

    similar_videos := SelectableTableView {
        visible: GuiState.active_tab == ActiveTab.SimilarVideos;
        min-width: 200px;
        height: parent.height;
        columns <=> Settings.similar_videos_column_name;
        column_sizes <=> Settings.similar_videos_column_size;
        values <=> similar_videos_model;
        parentPathIdx: 3;
        fileNameIdx: 2;
    }

    similar_music := SelectableTableView {
        visible: GuiState.active_tab == ActiveTab.SimilarMusic;
        min-width: 200px;
        height: parent.height;
        columns <=> Settings.similar_music_column_name;
        column_sizes <=> Settings.similar_music_column_size;
        values <=> similar_music_model;
        parentPathIdx: 9;
        fileNameIdx: 2;
    }

    invalid_symlink := SelectableTableView {
        visible: GuiState.active_tab == ActiveTab.InvalidSymlinks;
        min-width: 200px;
        height: parent.height;
        columns <=> Settings.invalid_symlink_column_name;
        column_sizes <=> Settings.invalid_symlink_column_size;
        values <=> invalid_symlinks_model;
        parentPathIdx: 2;
        fileNameIdx: 1;
    }

    broken_files := SelectableTableView {
        visible: GuiState.active_tab == ActiveTab.BrokenFiles;
        min-width: 200px;
        height: parent.height;
        columns <=> Settings.broken_files_column_name;
        column_sizes <=> Settings.broken_files_column_size;
        values <=> broken_files_model;
        parentPathIdx: 2;
        fileNameIdx: 1;
    }

    bad_extensions := SelectableTableView {
        visible: GuiState.active_tab == ActiveTab.BadExtensions;
        min-width: 200px;
        height: parent.height;
        columns <=> Settings.bad_extensions_column_name;
        column_sizes <=> Settings.bad_extensions_column_size;
        values <=> bad_extensions_model;
        parentPathIdx: 2;
        fileNameIdx: 1;
    }

    settings_list := SettingsList {
        visible: GuiState.active_tab == ActiveTab.Settings;
    }

    about_app := About {
        visible: GuiState.active_tab == ActiveTab.About;
    }

    public function reset_selection() {
        if (GuiState.active_tab == ActiveTab.EmptyFiles) {
            empty_files.reset_selection();
        } else if (GuiState.active_tab == ActiveTab.EmptyFolders) {
            empty_folders.reset_selection();
        } else if (GuiState.active_tab == ActiveTab.SimilarImages) {
            similar_images.reset_selection();
        } else if (GuiState.active_tab == ActiveTab.BadExtensions) {
            bad_extensions.reset_selection();
        } else if (GuiState.active_tab == ActiveTab.BigFiles) {
            big_files.reset_selection();
        } else if (GuiState.active_tab == ActiveTab.DuplicateFiles) {
            duplicates.reset_selection();
        } else if (GuiState.active_tab == ActiveTab.TemporaryFiles) {
            temporary_files.reset_selection();
        } else if (GuiState.active_tab == ActiveTab.SimilarVideos) {
            similar_videos.reset_selection();
        } else if (GuiState.active_tab == ActiveTab.SimilarMusic) {
            similar_music.reset_selection();
        } else if (GuiState.active_tab == ActiveTab.InvalidSymlinks) {
            invalid_symlink.reset_selection();
        } else if (GuiState.active_tab == ActiveTab.BrokenFiles) {
            broken_files.reset_selection();
        } else {
            // debug("Non handled reset selection in main_lists.slint", GuiState.active_tab);
        }
    }

    changed_active_tab() => {
        // TODO - not sure why this exists, but if needed it needs to be updated to use new functions
        // empty_folders.deselect_selected_item();
        // empty_files.deselect_selected_item();
        // similar_images.deselect_selected_item();
    }
}
